#include <drivers/framebuffer.h>
#include <kernel/syslog.h>


struct framebuffer* fb_dev[2] = {NULL, NULL};


int framebuffer_register(struct framebuffer *fb)
{
    int id = 0;
    
    if(fb_dev[0] != NULL && fb_dev[1] != NULL) {
        SYSLOG_ERROR("framebuffer: too many framebuffer devices");
        return -1;
    }

    if(fb_dev[0] == NULL) {
        fb_dev[0] = fb;
        id = 0;
    }
    else {
        fb_dev[1] = fb;
        id = 1;
    }

    SYSLOG_INFO("framebuffer: registered device %s", fb->name);
    return id;
}


int framebuffer_unregister(struct framebuffer *fb)
{
    int id = 0;

    if(fb_dev[0] == fb) {
        fb_dev[0] = NULL;
        id = 0;
    }
    else if(fb_dev[1] == fb) {
        fb_dev[1] = NULL;
        id = 1;
    }
    else {
        SYSLOG_ERROR("framebuffer: device %s not registered", fb->name);
        return -1;
    }

    SYSLOG_INFO("framebuffer: unregistered device %s", fb->name);
    return id;
}

